"use strict";
{
    class Queue {
        constructor() {
            this.dataStore = [];
        }
        get length() {
            return this.dataStore.length;
        }
        enqueus(element) {
            this.dataStore.push(element);
        }
        dequeus() {
            return this.dataStore.shift();
        }
        front() {
            return this.dataStore[0];
        }
        back() {
            return this.dataStore[this.length - 1];
        }
        toString() {
            return this.dataStore.map((item) => item).join("\n");
        }
        clear() {
            this.dataStore.length = 0;
        }
        isEmpty() {
            return this.length === 0;
        }
    }
    // let que = new Queue<String>();
    // que.enqueus("Jimmy");
    // que.enqueus("xuexue");
    // que.enqueus("Jack");
    // que.enqueus("Henry");
    // console.log(que.front());
    // console.log(que.back());
    // console.log(que.dequeus());
    // console.log(que.length);
    // console.log(que.toString());
    // console.log(que.clear());
    // console.log(que.isEmpty());
    let queues = [];
    for (var i = 0; i < 10; ++i) {
        queues[i] = new Queue();
    }
    let nums = [];
    for (var i = 0; i < 10; ++i) {
        nums[i] = Math.floor(Math.floor(Math.random() * 101));
    }
    console.log("BEFORE", nums);
    const distribute = (nums, queues, n, digit) => {
        for (let i = 0; i < n; i++) {
            if (digit == 1) {
                queues[nums[i] % 10].enqueus(nums[i]);
            }
            else {
                queues[Math.floor(nums[i] / 10)].enqueus(nums[i]);
            }
        }
    };
    const collect = (queuss, nums) => {
        let i = 0;
        for (let digit = 0; digit < 10; digit++) {
            while (!queuss[digit].isEmpty()) {
                nums[i++] = queuss[digit].dequeus();
            }
        }
    };
    // 第一次收集
    distribute(nums, queues, 10, 1);
    collect(queues, nums);
    // 第二次收集
    distribute(nums, queues, 10, 10);
    collect(queues, nums);
    console.log("NOW", nums);
}
